package com.oyjd.beauty.business.kid.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oyjd.beauty.bean.po.Kidney;
import com.oyjd.beauty.bean.vo.KidneyVO;
import com.oyjd.beauty.business.kid.dao.KidDao;
import com.oyjd.beauty.business.kid.service.KidService;
import com.oyjd.beauty.fw.action.Page;

/**
 * 
 * 性格信息业务接口实现
 * 
 * @author <b>欧建东<br/>
 *         Email:oyjd@163.com</b>
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class KidServiceImpl implements KidService {
	private KidDao dao;

	@Autowired
	public void setDao(KidDao dao) {
		this.dao = dao;
	}

	/**
	 * 获取性格信息列表数据
	 * 
	 * @param page
	 *            页面对象
	 * @return
	 */
	public Page<KidneyVO> getList(Page<KidneyVO> page) {
		return dao.getList(page);
	}

	/**
	 * 根据ID获取性格信息对象信息
	 * 
	 * @param id
	 *            ID
	 * @return
	 */
	public KidneyVO getKidneyVO(String kidId) {
		return dao.getKidneyVO(kidId);
	}

	/**
	 * 增加性格信息
	 * 
	 * @param name
	 *            名称
	 * @param note
	 *            描述
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void add(String name, String note, String user) {
		Date date = new Date();
		Kidney kidney = new Kidney();
		kidney.setName(name);
		kidney.setNote(note);
		kidney.setCreator(user);
		kidney.setCreateTime(date);
		kidney.setLastEditor(user);
		kidney.setLastUpdateTime(date);
		kidney.setStatus(0);
		dao.create(kidney);
	}

	/**
	 * 修改性格信息
	 * 
	 * @param kidId
	 *            性格ID
	 * @param name
	 *            名称
	 * @param note
	 *            描述
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void edit(String kidId, String name, String note, String user) {
		Date date = new Date();
		Kidney kidney = (Kidney) dao.queryById(Kidney.class, kidId);
		kidney.setKidId(kidId);
		kidney.setName(name);
		kidney.setNote(note);
		kidney.setLastEditor(user);
		kidney.setLastUpdateTime(date);
		dao.update(kidney);
	}

	/**
	 * 删除性格信息
	 * 
	 * @param ids
	 *            多个ID
	 * @param user
	 *            当前用户
	 * @return
	 */
	@Transactional(readOnly = false)
	public void remove(String[] ids, String user) {
		dao.remove(ids, user);
	}

}
